<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            quick-search-placeholder="根据分类名称模糊查询" />
        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table />

        <PopupForm ref="formRef" />
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import PopupForm from './popupForm.vue'
import { useI18n } from 'vue-i18n'
import { baTableApi } from '/@/api/common'
import baTableClass from '/@/utils/baTable'

defineOptions({
    // eslint-disable-next-line vue/multi-word-component-names
    name: 'class/index',
})

const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/v1/live/list/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: 'ID', prop: 'id', align: 'center', operator: false, },
            { label: '视频名称', prop: 'live_name', align: 'center', operator: 'LIKE', operatorPlaceholder: '请输入视频名称' },
            { label: '封面图', prop: 'live_image', align: 'center', render: 'image', operator: false },
            { label: '直播人', prop: 'author_name', align: 'center', operator: 'LIKE', operatorPlaceholder: '请输入直播人' },
            { label: '播放地址', prop: 'play_url', align: 'center', operator: 'LIKE', operatorPlaceholder: '请输入播放地址' },
            
            {
                label: '赛事类型',
                prop: 'type',
                align: 'center',
                render: 'tag',
                custom: { 'football': 'danger', 'basketball': 'success' },
                replaceValue: { 'football': '足球', 'basketball': '篮球' },
            },
            {
                label: '是否收费',
                prop: 'is_charges',
                align: 'center',
                render: 'tag',
                custom: { '0': 'danger', '1': 'success' },
                replaceValue: { '0': '免费', '1': '收费' },
            },
            {
                label:'创建时间',
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                sortable: 'custom',
                operator: false,
            },
            { label: t('Operate'), align: 'center', width: '130', render: 'buttons', operator: false, buttons: defaultOptButtons(['edit', 'delete']) }
        ],
    },
    {
        defaultItems: {
            type:'football',
            is_charges: 0,
            weigh: 0,
        },
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.dragSort()
    })
})
</script>

<style scoped lang="scss"></style>
